﻿define('provider',
    ['ko','formActions'],
 function (ko, formActions) {
     var provider = function () {
         var self = this;
         self.templateName = "provider";
         self.deleteController = "/api/Providers/Delete/";
         self.id = ko.observable();
         self.lastName = ko.observable().extend({ validationEvent: "log: lastName" });
         self.firstName = ko.observable().extend({ validationEvent: "log: firstName" });
         self.idnp = ko.observable().extend({ validationEvent: "log: IDNP" });
         
         self.departmentId = ko.observable().extend({ validationEvent: "log: department" });
         self.departmentName = ko.observable();
         self.DepartmentAutocomplete = function (suggestion) {
             self.departmentId(suggestion.data);
             self.departmentName(suggestion.value);
         };

         self.specialityId = ko.observable().extend({ validationEvent: "log: speciality" });
         self.specialityName = ko.observable();
         self.SpecialityAutocomplete = function (suggestion) {
             self.specialityId(suggestion.data);
             self.specialityName(suggestion.value);
         };

         self.positionId = ko.observable();
         self.positionName = ko.observable();
         self.PositionAutocomplete = function (suggestion) {
             self.positionId(suggestion.data);
             self.positionName(suggestion.value);
         };

         self.serviceRoom = ko.observable();
         self.createdOn = ko.observable();
         
         self.load = function(d) {
             self.id(d.id);
             self.lastName(d.lastName);
             self.firstName(d.firstName);
             self.idnp(d.idnp);

             self.departmentId(d.departmentId);
             if (d.department!=null)self.departmentName(d.department.title);

             self.positionId(d.positionId);
             if (d.position!=null) self.positionName(d.position.title);

             self.specialityId(d.specialityId);
             if(d.speciality!=null)self.specialityName(d.speciality.title);

             self.serviceRoom(d.serviceRoom);

             self.createdOn(d.createdOn);
         };

         self.save = function() {
             toastr.success("Providers saved");
         };
         
         var formAction = new formActions("/api/Providers/", self);
         self.validation = function () { formAction.validation(); };
         self.clearValidation = function () { formAction.clearValidation(); };
         self.save = function (parent, dlg) { formAction.save(parent, dlg); };
     };

     return provider;

 });